#include<bits/stdc++.h>
using namespace std;
int T,n,a[200002];
int ans;
void dfs(int cur,int col,int lrs=0,int lbs=0,int sum=0){
	if(cur==n+1){
		ans=max(ans,sum);
		return;
	}
	
	if(col==1&&lrs==a[cur])sum+=a[cur];
	else if(col==2&&lbs==a[cur])sum+=a[cur];
	
	if(col==1)lrs=a[cur];
	else lbs=a[cur];
	
	dfs(cur+1,1,lrs,lbs,sum);dfs(cur+1,2,lrs,lbs,sum);
}
int main(){
	//Do not forget to freopen!
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	for(cin>>T;T;T--){
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		ans=0;
		dfs(1,1);
		cout<<ans<<endl;
	}
	return 0;
}
